package goodenglish.interfaces.studyword;

import goodenglish.domain.model.lexicon.Lexicon;
import goodenglish.domain.model.lexicon.LexiconRepository;
import goodenglish.infrastructure.repository.db.LexiconRepositoryDb;
import goodenglish.interfaces.BeanFactory;
import goodenglish.interfaces.LexiconChoiceBox;
import goodenglish.interfaces.Main;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;

public class NewOrOldStudyPlanSelectDlg extends BorderPane {
	final LexiconChoiceBox lexiconCbx = new LexiconChoiceBox();
	final RadioButton studyNewRbtn;
	final RadioButton reviewOldRbtn;
	private ToggleGroup tg;

	public NewOrOldStudyPlanSelectDlg() {
		this.getStyleClass().add("messageDialog");
		setMaxSize(500, 350);
		this.setTop(new Label("单词学习向导"));
		this.setLeft(lexiconCbx);
		VBox vBox = new VBox();
		tg = new ToggleGroup();
		studyNewRbtn = new RadioButton("学习新单词");
		studyNewRbtn.setSelected(true);
		studyNewRbtn.setToggleGroup(tg);
		reviewOldRbtn = new RadioButton("复习原来的单词");
		reviewOldRbtn.setToggleGroup(tg);

		vBox.getChildren().addAll(studyNewRbtn, reviewOldRbtn);
		this.setCenter(vBox);
		addBottom();

	}

	private void addBottom() {
		Button reviewBtn = new Button("下一步");
		reviewBtn.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				Lexicon lexicon = lexiconCbx.getSelectLexicon();
				
				if (null == lexicon) {
					return;
				}
				if (studyNewRbtn.isSelected()) {
					Main.instance.showModalMessage(new CreateStudyPlanDlg(lexicon));

				}
				if (reviewOldRbtn.isSelected()) {
					Main.instance.showModalMessage(new SelectStudyPlanDlg(lexicon));
				}

			}
		});
		this.setBottom(reviewBtn);
	}

	private LexiconRepository lexiconRepository = BeanFactory.getSingleInstance(LexiconRepositoryDb.class);
}
